package org.spdata.tsdb.controller;


import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spdata.tsdb.client.Query;
import org.spdata.tsdb.dao.MetricDAO;
import org.spdata.tsdb.dto.DataPoints;
import org.spdata.tsdb.dto.Response;
import org.spdata.tsdb.service.DataPointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/query")
public class QueryController {
	static Logger logger = LoggerFactory.getLogger(QueryController.class);
	@Autowired
	DataPointService service;
	
	@Autowired
	MetricDAO metricDAO = null;
	
	@RequestMapping("")
	@ResponseBody
	public Response doQuery(@RequestBody Query query){
		Response response = null;
		try{
			List<DataPoints> dps = service.query(query);
			response = Response.success(dps);
		}catch(Exception e){
			logger.error("failed to query!",e);
			response = Response.error(e.getMessage());
		}
		return response;
	}
}	
